const path = require('path');
const http = require('http');
const server = http.createServer();
const electron = require("electron");
const app = electron.app;
const BrowserWindow = electron.BrowserWindow;
const IpcMain = electron.ipcMain;

server.on('request', function (req, res) {
  if (req.url === '/favicon.ico') return res.end('OK');
  res.end('success');
});

server.listen(5000);

var window = null;

app.on("ready", function () {
  window = new BrowserWindow({
    width: 1000, height: 777,
    center: true,
    frame: false,
    transparent: true,
    resizable: false,
    maximizable: false,
    fullscreen: false,
    webPreferences: {
      enableRemoteModule: true, // 启用渲染进程 Remote
      webSecurity: false, // 关闭安全模式
      nodeIntegration: true, // 启用 node
      nodeIntegrationInWorker: true, // 启用多进程 node
      webviewTag: true, // 启用 webview
    }
  });
  window.loadFile(path.join(__dirname, 'index.html'))

  window.webContents.openDevTools()

  window.hookWindowMessage(0x116, function (e) {
    window.setEnabled(false);
    setTimeout(() => {window.setEnabled(true);}, 100);
    return true;
  })
});


IpcMain.on('asynchronous-message', function (event, arg) {
  console.log('收到消息')
  console.log(arg);  // prints "ping"
  event.sender.send('asynchronous-reply', 'pong');
});

// tasklist|findstr "QQMusic"
// wmic process where processid=10728 get executablepath
